/* 
 * File:   read_config.h
 * Author: oddi
 *
 * Created on January 20, 2010, 11:51 AM
 */

#ifndef _READ_CONFIG_H
#define	_READ_CONFIG_H

#ifdef	__cplusplus
extern "C" {
#endif
    
    #include "libconfig.h"
    #include "gsl/gsl_vector.h"
    #include "gsl/gsl_matrix.h"

    /*Paths to variables in config file*/
    #define PATH_NUM_OF_Z_ELECTRONS "simulation.NumOfZElectrons"
    #define PATH_NUM_OF_TR_ELECTRONS "simulation.NumOfTrElectrons"
    #define PATH_TEMPERATURE_X "simulation.TemperatureX"
    #define PATH_TEMPERATURE_Y "simulation.TemperatureY"
    #define PATH_TEMPERATURE_Z "simulation.TemperatureZ"
    #define PATH_E0 "simulation.E0"
    #define PATH_B0 "simulation.B0"
    #define PATH_N0 "simulation.n0"
    #define PATH_PULSE_DURATION "simulation.PulseDuration"
    #define PATH_PULSE_DELAY "simulation.PulseDelay"
    #define PATH_PULSE_LENGTH "simulation.PulseLength"
    #define PATH_PULSE_Z_SHIFT "simulation.PulseZShift"
    #define PATH_DZ "simulation.Dz"
    #define PATH_Z_COLLECT_POINTS "simulation.z_collect_points"
    #define PATH_TIME_COLLECT_POINTS "simulation.time_collect_points"
    #define PATH_ABS_ERR "simulation.eps_abs"
    #define PATH_REL_ERR "simulation.eps_rel"

    #define PATH_SAVEDIR "environment.savedir"
    #define PATH_TEMPDIR "environment.tempdir"
    #define PATH_NAME_TEMPLATE "environment.name_template"

    /*columns assignation in speed distribution arrays*/
    #define COLUMN_ZSPEED_PDF   0
    #define COLUMN_ZSPEED_VALUE 1

    #define COLUMN_XSPEED_PDF   0
    #define COLUMN_XSPEED_VALUE 1

    #define COLUMN_YSPEED_PDF   2
    #define COLUMN_YSPEED_VALUE 3

    /*simulation paramaters structure
     *all values in CGSE system
     */
    typedef struct simp
    {
        /*number of electrons with various z speed*/
        int NumOfZElectrons;

        /*number of electrons with various transverse speed (separately)*/
        int NumOfTrElectrons;

        /*temperatures*/
        double TemperatureX;
        double TemperatureY;
        double TemperatureZ;

        /*electric field amplitude*/
        double E0;

        /*magnetic field amplitude*/
        double B0;

        /*plasma density*/
        double n0;

        /*pulse duration*/
        double PulseDuration;

        /*pulse delay related to t = 0*/
        double PulseDelay;

        /*pulse length*/
        double PulseLength;

        /*pulse space shift (related to z = 0)*/
        double PulseZShift;
        /*delta z*/
        double dz;

        /*array with space collect points*/
        gsl_vector* z_collect_points;

        /*array with time collect points*/
        gsl_vector* time_collect_points;

        /*absolute accuracy o the solution*/
        double abs_eps;

        /*relative accuracy o the solution*/
        double rel_eps;

        char* savedir;
        char* tempdir;
        char* name_template;

    } simp_t;

    typedef struct calculated_sim_parameters
    {
        /*storage for pulse*/
        /*row - time coordinate, col - space coordinate*/
        gsl_matrix* pulse;

        /*storage for pulse z variative*/
        gsl_matrix* pulse_dz;

        /*storage for pulse t variative*/
        gsl_matrix* pulse_dt;

        /*storage for initial transversal speed distribution*/
        gsl_matrix* trsd;

        /*storage for initial z speed distribution*/
        gsl_matrix* zsd;

        /*delta t*/
        double dt;

        /*electron cyclotrone freq*/
        double w_ce;

        /*storage for time points where pulse exists*/
        gsl_vector* pulse_time;

        /*storage for z points where pulse exists*/
        gsl_vector* pulse_z;
    }csimp_t;

    typedef struct full_system_parameters
    {
        simp_t* simp;
        csimp_t* csimp;
    }fsp_t;

    /*
     *Interface function
     */

    int conf_read_simulation_config(const char*, fsp_t*);

    int conf_generate_calculated_parameters(fsp_t*,
            double (*time_envelope)(fsp_t*, double),
            double (*time_filling)(fsp_t*, double),
            double(*space_envelope)(fsp_t*, double));


    int conf_free_configuration(fsp_t*);

#ifdef	__cplusplus
}
#endif

#endif	/* _READ_CONFIG_H */